<?php

include_once('logic/action/Action.php');
include_once('logic/view/approve_view.php');

class ApproveAction extends Action
{
	public function perform()
	{
		$photos = new PhotosDAO();
		$comments = new CommentsDAO();
		$view = new ApproveView();

		if (Session::getSessionVar ("logged_in") == 'true')
		{
			$view->setParam('_user_logged_in', 'true');
			if (HttpRequest::getRequest('form_posted') == 'posted')
			{
				$photoId = HttpRequest::getRequest('id');
				$approveStatus = HttpRequest::getRequest('approved');
				$date = HttpRequest::getRequest('date');
				if (($photoId != '')&&(date !=''))
				{
					if($approveStatus == 1) {
						$comments->activateComment($photoId, $date);
					} else {
						$comments->deleteComment($photoId, $date);
					}
				}

				$comments = $comments->getPendingComments(0);
				foreach ($comments as $comment)
				{
						$view->addComment($comment[0],$comment[1],$comment[2],$comment[3]);
				}
			} else {

				$comments = $comments->getPendingComments(0);
				foreach ($comments as $comment)
				{
						$view->addComment($comment[0],$comment[1],$comment[2],$comment[3]);
				}
			}
		} else {
			$view->setParam('_user_logged_in', 'false');
		}
		parent::setCommonParams($view);
		$view->display();
	}
}

?>
